package logic

import (
	"context"
	"mall_srv/goodclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodsAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsAddLogic {
	return &GoodsAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodsAddLogic) GoodsAdd(req *types.GoodsAddrequest) (resp *types.Response, err error) {
	add, err := l.svcCtx.GoodSrv.GoodsAdd(l.ctx, &goodclient.GoodsAddRequest{
		GoodsTitle: req.GoodsTitle,
		GoodsImage: req.GoodsImage,
		GoodsPrice: float32(req.GoodsPrice),
		GoodsStock: req.GoodsStock,
		GoodStatus: req.GoodStatus,
		Status:     req.Status,
	})
	if err != nil {
		return &types.Response{
			Msg:  err.Error(),
			Data: nil,
			Code: 500,
		}, nil
	}

	return &types.Response{
		Msg:  "商品发布成功",
		Data: add,
		Code: 200,
	}, nil
}
